package com.sa.token.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @desc： mybatis-plus 新增和更新时自动填充时间
 * @author： xhs
 * @date： 2021/8/29 15:32
 * @version： JDK 1.8
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("自动填充《createTime》");
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("自动填充《updateTime》");
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
